/**
 * 项目名称：MCOMMON
 * 包名称：com.mt.common.sys.domain
 * 文件名称：LoginLog.java
 */
package com.mt.system.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.mt.component.domain.Common;
import com.mt.utils.StringUtils;



/**
 * 类名称：LoginLog <br>
 * 类描述：登录日志 <br>
 * 创建人： 马腾 <br>
 * 创建时间：2012-10-18 下午11:30:43 <br>
 */
@Entity  
@Table(name="CFG_LOG_LOGIN")
public class LoginLog extends Common implements Serializable {

	private static final long serialVersionUID = 2807957269162050895L;

	private User user;//登录用户
	private Date loginTime;//用户登录时间
	private String loginIp;//登录IP地址
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "USER_ID")
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LOGIN_TIME")
	public Date getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}
	
	@Column(name = "LOGIN_IP", length = 32)
	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof LoginLog){
			LoginLog loginLog = (LoginLog)obj;
			if(StringUtils.isEmpty(loginLog.getId())) return false;
			return loginLog.getId().equals(getId());
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return getId()==null ? 0 : getId().hashCode();
	}
	
	@Override
	public String toString() {
		return LoginLog.class.getName() + "[" + id + "]";
	}
}
